package New;

import java.util.Arrays;

public class quickSortDemo{
    public static void main(String[] args) {
        int [] array = new int []{1,51,12,45,33,79,9};
       quickSort(array,0,array.length-1);
        System.out.println(Arrays.toString(array));
    }
    public static int [] quickSort(int array [] ,int start ,int end){
        int target = array[start];
        int i = 0;
        int j = end;
        while (i<j){
            while ((i<j)&&array[j]>target){
                j--;
            }while ((i<j)&&array[i]<target){
                i++;
            }
            if ((array[i]==array[j])&&(i<j)){
                j++;
            }else {
                int temp = array[i];
                array [i] = array[j];
                array [j] = temp;
            }
        }
        if (i-1>start) array = quickSort(array,start,i-1);
        if (j+1<end) array = quickSort(array,j+1,end);
    return array;
    }
}
